package com.taobao.me.service.impl;

import com.taobao.base.model.RestResponse;
import com.taobao.me.mapper.UsersMapper;
import com.taobao.me.model.dto.UserDto;
import com.taobao.me.model.po.Users;
import com.taobao.me.service.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UsersMapper usersMapper;



    @Override
    public RestResponse<UserDto> getUserById(int userId) {

        if (userId != 0) {
            Users user = usersMapper.selectByUserId(userId);
            UserDto userDto = new UserDto();
            BeanUtils.copyProperties(user, userDto);

            return RestResponse.success(userDto);
        }

        return RestResponse.validfail("用户id不能为空");
    }

    @Override
    public RestResponse<String> insertUser(Users users) {

        int insert = usersMapper.insert(users);
        if (insert > 0) {
            return RestResponse.success("新增用户成功");
        }
        return RestResponse.validfail("新增用户失败");
    }
}
